/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.form;

import org.rails.extjs.BoxComponent;
import org.rails.extjs.Option;

public abstract class Field extends BoxComponent {
	

	public static final String MSG_TARGET = "qtip";
	public static final String MSG_TITLE = "title";
	public static final String MSG_UNDER = "under";
	public static final String MSG_SIDE = "side";

	public Field() {
		super();
	}

	public Field(Option configOptions) {
		super(configOptions);
	}
	
	public Field(String name) {
		super();
		setName(name);
	}

	public Field(String name,String fieldLabel) {
		super();
		setName(name);
		setFieldLabel(fieldLabel);
	}
	
	public Field(String name,String fieldLabel,Object value) {
		super();
		setName(name);
		setFieldLabel(fieldLabel);
		setValue(value);
	}
	
	public void setAutoCreate(Tag autoCreate){
		addOption("autoCreate", autoCreate);
	}
	
	public Tag getAutoCreate(){
		return getOption("autoCreate") == null ? new Tag("input","text",20,"off") : (Tag)getOption("autoCreate");
	}
	
	public void setFieldClass(String fieldClass){
		addOption("fieldClass", fieldClass);
	}
	
	public String getFieldClass(){
		return getString("fieldClass","x-form-field");
	}
	
	public void setFocusClass(String focusClass){
		addOption("focusClass", focusClass);
	}
	
	public String getFocusClass(){
		return getString("focusClass","x-form-focus");
	}
	
	public void setInputType(String inputType){
		addOption("inputType", inputType);
	}
	
	public String getInputType(){
		return getString("inputType","text");
	}
	
	public void setInvalidClass(String invalidClass){
		addOption("invalidClass",	invalidClass);
	}
	
	public String getInvalidClass(){
		return getString("invalidClass","x-form-invalid");
	}
	
	public void setInvalidText(String invalidText){
		addOption("invalidText", invalidText);
	}
	
	public String getInvalidText(){
		return getString("invalidText","The value in this field is invalid");
	}
	
	public void setMsgFx(String msgFx){
		addOption("msgFx",msgFx);
	}

	public String getMsgFx(){
		return getString("msgFx","normal");
	}
	
	public void setMsgTarget(String msgTarget){
		addOption("msgTarget", msgTarget);
	}
	
	public String getMsgTarget(){
		return getString("msgTarget","qtip");
	}
	
	public void setName(String name){
		addOption("name", name);
	}
	
	public String getName(){
		return getString("name","");
	}
	
	public void setPreventMark(Boolean preventMark){
		addOption("preventMark", preventMark);
	}
	
	public Boolean isPreventMark(){
		return getBoolean("preventMark",false);
	}

	public void setReadOnly(Boolean readOnly){
		addOption("readOnly", readOnly);
	}
	
	public Boolean isReadOnly(){
		return getBoolean("readOnly", false);
	}
	
	public void setTabIndex(Integer tabIndex){
		addOption("tabIndex", tabIndex);
	}
	
	public Integer getTabIndex(){
		return getInteger("tabIndex", 0);
	}
	
	public void setValidateOnBlur(Boolean validateOnBlur){
		addOption("validateOnBlur", validateOnBlur);
	}
	
	public Boolean isValidateOnBlur(){
		return getBoolean("validateOnBlur", true);
	}
	
	public void setValidationDelay(Number validationDelay){
		addOption("validationDelay", validationDelay);
	}
	
	public Integer isValidationDelay(){
		return getInteger("validationDelay", 250);
	}
	
	public void setValidationEvent(Object validationEvent){
		addOption("validationEvent", validationEvent);
	}
	
	public Object getValidationEvent(){
		return getOption("validationEvent");
	}
	
	public void setValue(Object value){
		addOption("value", value);
	}
	
	public Object getValue(){
		return getOption("value");
	}
	

}
